package com.yy.invoice.controller;


import com.yy.invoice.entity.Invoice;
import com.yy.invoice.entity.Result;
import com.yy.invoice.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("file")
@Slf4j
@Api(tags = "文件管理")
public class FileController {

    @Autowired
    private FileService fileService;

    @ApiOperation("上传文件")
    @PostMapping("/upload")
    public Result fileUpload(@ApiParam("上传的文件（数组）") @RequestParam("file") MultipartFile[] files, @ApiParam("上传的月份") @RequestParam("value") String month, HttpServletRequest request){
        return fileService.upload(files,month,request);
    }

    @ApiOperation("生成Excel")
    @PostMapping("/excel")
    public Result download(@ApiParam("前端的发票信息") @RequestBody List<Invoice> invoices,HttpServletRequest request){
        return fileService.toExcel(invoices,request);
    }
    @ApiOperation("多张发票合并成一张发票")
    @PostMapping("/pdfs2Pdf")
    public Result pdfs2Pdf(@RequestBody List<Invoice> invoices, HttpServletRequest request){
        return fileService.pdfs2Pdf(invoices,request);
    }

    @ApiOperation("生成压缩包")
    @PostMapping("/getZip")
    public Result getZip(@RequestBody List<Invoice> invoices,HttpServletRequest request){
        return fileService.getZip(invoices,request);
    }
}
